package DuiXingShuZu_4;

import DuiXingShuZu_3.Phone;

public class GirlFriendsTest {
    private static GirlFriends gir;

    public static void main(String[] args) {
        //定义数组存储4个女朋友的对象
        //女朋友的属性：姓名、年龄、性别、爱好
        //要求1：计算出4个女朋友的平均年龄
        //要求2：统计年龄比平均年龄低的女朋友有几个并把她们的所有信息打印出来

        //1.创建数组存储对象
        GirlFriends[] arr = new GirlFriends[4];

        //2.创建对象
        GirlFriends g1 = new GirlFriends("小红",19,'女',"打网球");
        GirlFriends g2 = new GirlFriends("小美",18,'女',"打火影");
        GirlFriends g3 = new GirlFriends("小芳",21,'女',"健身");
        GirlFriends g4 = new GirlFriends("小丽",17,'女',"打瓦");

        //3.把对象的数据存放到数组中
        arr[0] = g1;
        arr[1] = g2;
        arr[2] = g3;
        arr[3] = g4;

        //4.求平均年龄
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriends girl = arr[i];//定义一个变量girl去接收数组对应元素值
            sum = sum + girl.getAge();
        }
        int avg = sum / arr.length;
        System.out.println(avg);

        //5.统计比平均年龄低的女士
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriends girl = arr[i];
            if (girl.getAge() < avg){
                girl.showRoleInfo();
                System.out.println(" ");
                count++;
            }
        }
        System.out.println("比平均年龄小的有" + count + "个");
    }
}
